<template>
  <div>
    <el-button type="primary" @click="willAdd">添加</el-button>
    <v-list :user="user" :list="list" @init="init" @willEdit="willEdit"></v-list>
    <v-from ref="form" :user="user" @init="init"></v-from>
    <!-- 一定要注意page-size -->
    <el-pagination
      background
      @current-change="changePage"
      layout="prev, pager, next"
      :total="count"
      :page-size="size"
    ></el-pagination>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import vFrom from "./components/from.vue";
import vList from "./components/list.vue";
import { reqmenuList, } from "../../request/api";
export default {
  components: {
    vFrom,
    vList,
  },
  data() {
    return {
      user: {
        isshow: false,
        isAdd: true,
      },
      list: [],
    };
  },
  mounted() {
    // this.init();
    // this.reqCount();
    // this.reqList()
    // console.log(this.count);
  },
  computed: {
    ...mapGetters({
      count: "shopSpecs/count",
      size: "shopSpecs/size",
      page: "shopSpecs/page",
    }),
  },
  methods: {
    ...mapActions({
      reqCount: "shopSpecs/reqCount",
      reqList: "shopSpecs/reqLists",
      changePage: "shopSpecs/reqPageChange",
    }),
    // 点了添加
    willAdd() {
      this.user.isshow = true;
      this.user.isAdd = true;
    },
    // 点了编辑
    willEdit(id) {
      this.user.isshow = true;
      this.user.isAdd = false;
      this.$refs.form.getOne(id);
    },
    init() {
      // reqmenuList({
      //   istree: true,
      // }).then((res) => {
      //   // console.log(res);
      //   if (res.data.code === 200) {
      //     this.list = res.data.list;
      //   }
      // });
    },
  },
};
</script>

<style lang='less' scoped>
@import "../../less/index.less";
.el-button {
  margin-bottom: @margin;
}
</style>